using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using DirkRettschlag.Utils;

namespace Departure
{
    public class ctrlStationListItem : KListControl.IKListItem, IDisposable
    {

        #region Delegates


        #endregion Delegates

        #region Events


        #endregion Events

        #region Variables

        string stationName = string.Empty;

        string key = string.Empty;

        private StringFormat m_stringFormat = new StringFormat();
        private KListControl m_parent;
        private Rectangle m_bounds;
        private int m_x = -1;
        private int m_y = -1;

        private string m_text;
        private object m_value;
        private bool m_selected = false;
        private string fastAccessValue;

        SolidBrush solidBrushFontColor;
        SolidBrush solidBrushLaterColor;

        Rectangle rectangleBackGroundItem;
        Rectangle rectangleBackGroundItemSelected;


        private bool vga = false;
       
        #endregion Variables

        #region Constructor

        public ctrlStationListItem()
        {
            m_stringFormat.Alignment = StringAlignment.Near;
            m_stringFormat.FormatFlags = StringFormatFlags.NoWrap;
        }

        public ctrlStationListItem(KListControl parent, string stationName, string key, bool vga)
        {
            this.stationName = stationName;
            this.Text = stationName; // used for sorting
            this.key = key;
            this.vga = vga;
            this.m_parent = parent;
            
            m_stringFormat.Alignment = StringAlignment.Near;
            m_stringFormat.FormatFlags = StringFormatFlags.NoWrap;

            solidBrushFontColor = new SolidBrush(m_parent.SkinSettings.FontColor);
            solidBrushLaterColor = new SolidBrush(m_parent.SkinSettings.LaterColor);

            rectangleBackGroundItemSelected = new Rectangle(0, 0, m_parent.SkinSettings.BackGroundItemSelected.Width, m_parent.SkinSettings.BackGroundItemSelected.Height);
            rectangleBackGroundItem = new Rectangle(0, 0, m_parent.SkinSettings.BackGroundItem.Width, m_parent.SkinSettings.BackGroundItem.Height);


        }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public virtual void Dispose()
        {
            m_parent = null;
        }

        #endregion Constructor

        #region Public Functions

        public void Render(Graphics g, Rectangle bounds)
        {
            if (m_parent != null)
            {
                SizeF size;

                if (vga)
                {
                    if (m_selected)
                        g.DrawImage(m_parent.SkinSettings.BackGroundItemSelected, bounds, rectangleBackGroundItemSelected, GraphicsUnit.Pixel);
                    else
                        g.DrawImage(m_parent.SkinSettings.BackGroundItem, bounds, rectangleBackGroundItem, GraphicsUnit.Pixel);

                    using (Font f2 = Utilities.AppropriateFont(g, 5, 14, new Size(bounds.Width - 56, bounds.Height), stationName, m_parent.Font, out size))
                    {
                        g.DrawString(stationName, f2, solidBrushFontColor, bounds.X + 56, bounds.Y + ((bounds.Height - size.Height) / 2));
                    }
                   
                }
                else
                {
                    if (m_selected)
                        g.DrawImage(m_parent.SkinSettings.BackGroundItemSelected, bounds, rectangleBackGroundItemSelected, GraphicsUnit.Pixel);
                    else
                        g.DrawImage(m_parent.SkinSettings.BackGroundItem, bounds, rectangleBackGroundItem, GraphicsUnit.Pixel);

                    using (Font f2 = Utilities.AppropriateFont(g, 5, 14, new Size(bounds.Width - 28, bounds.Height), stationName, m_parent.Font, out size))
                    {
                        g.DrawString(stationName, f2, solidBrushFontColor, bounds.X + 28, bounds.Y + ((bounds.Height - size.Height) / 2));
                    }
                }
            }
        }

        #endregion Public Functions

        #region Private Functions
                

        #endregion Private Functions

        #region Properties

        public bool VGA
        {
            get { return this.vga; }
            set
            {
                this.vga = value;

            }
        }

        public string StationName
        {
            get { return this.stationName; }
            set
            {
                this.stationName = value;
            }
        }

        public string Key
        {
            get
            {
                return this.key;
            }
            set
            {
                this.key = value;
            }
        }

        public KListControl Parent { get { return m_parent; } set { m_parent = value; } }

        public int XIndex { get { return m_x; } set { m_x = value; } }

        public int YIndex { get { return m_y; } set { m_y = value; } }

        public bool Selected { get { return m_selected; } set { m_selected = value; } }

        public object Value { get { return m_value; } set { m_value = value; } }

        public Rectangle Bounds { get { return m_bounds; } set { m_bounds = value; } }

        public string Text { get { return m_text; } set { m_text = value; } }

        public string FastAccessValue
        {
            get { return fastAccessValue; }
            set { fastAccessValue = value; }
        }

        #endregion Properties

    }
}
